package com.demo.controller;

import com.demo.dto.StageDto;
import com.demo.pojo.Project;
import com.demo.pojo.Stage;
import com.demo.service.StageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName StageController
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/7 19:43
 * @Version 1.0
 **/
@RestController
@RequestMapping("stage")
public class StageController {
    @Autowired
    StageService stageService;
    @RequestMapping("findAllDto")
    public List<StageDto> findAllDto(){
        return stageService.findAllDto();
    }

    @RequestMapping("updateStage")
    @ResponseBody
    public boolean updateStage(@RequestBody Stage stage){
        System.out.println("----------"+stage);
        stage.setUpdatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        System.out.println(stage);
        return stageService.updateStage(stage);
    }

    @RequestMapping("deleteStage")
    @ResponseBody
    public boolean deleteStage(String sid){
        return stageService.deleteStageById(sid);
    }

    @RequestMapping("insertStage")
    @ResponseBody
    public boolean insertStage(@RequestBody Stage stage){
        stage.setUpdatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return stageService.insertStage(stage);
    }

    @RequestMapping("findOne")
    @ResponseBody
    public StageDto findOneById(String sid){
        System.out.println(sid);
        return stageService.findOneById(sid);
    }
}
